package com.jiang.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * @author Jiang Junsheng
 * @create 2019/3/19
 * @since 1.0.0
 */
@Data
@ApiModel("分页")
public class PageUtils<T> {
	@ApiModelProperty(value = "当前页")
	private long currentPage;
	@ApiModelProperty(value = "每页数量")
	private long pageSize;
	@ApiModelProperty(value = "总条数")
	private long total;
	@ApiModelProperty(value = "总页数")
	private long totalPage;
	private List<T> records;

	public PageUtils(IPage page) {
		this.currentPage = page.getCurrent();
		this.pageSize = page.getSize();
		this.total = page.getTotal();
		this.totalPage = page.getPages();
		this.records = page.getRecords();
	}

	public static PageUtils wrapPage(IPage page){
		return new PageUtils(page);
	}
}
